<?php

//Tao MyController
class MyController extends CController
{

    public $token_const = 'qymzsTIXAEyU';
    public $layout      = '/layouts/main2';
    public $assetDir; //Khoi tao bien assetDir
    public $breadcrumbs = array();
    public $item_product_heiglight; //bai noi bat lon nhat ngoai trang chu
    public $list_product_heiglight; //danh sach bai noi bat ngoai trang chu
    public $category    = null; //ten danh muc
    public $meta_desc;
    public $meta_keywords;
    public $showBtn     = true;
    public $google_index;

    public function filters()
    {
        parent::filters();
        //Gan bien baseUrl vao bien assetDir
        $this->assetDir               = Yii::app()->theme->baseUrl . '/assets/';
        $this->meta_desc              = '';
        $this->meta_keywords          = '';
        //bai noi bat lon nhat ngoai trang chu
        $this->item_product_heiglight = Product::model()->findByPk(Option::getItem('item_on_homePage'));

        //danh sach bai noi bat ngoai trang chu

        $limit                        = Option::getItem('limit_project_hl') ? Option::getItem('limit_project_hl') : 9;
        $this->list_product_heiglight = Product::model()->findAll(array(
            'condition' => 'status = :s ',
            'params'    => array(':s' => Product::STATUS_HIGHLIGHT),
            'order'     => 'rank desc,id DESC',
            'limit'     => $limit
        ));
    }

    public function actions()
    {
        return array(
            'captcha' => array(
                'class'     => 'CCaptchaAction',
                'backColor' => 0xFFFFFF,
            ),
        );
    }

    public function getToken($data = array())
    {
        return md5(implode("+", $data) . $this->token_const);
    }

}
